home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-21 | 4.5 KB | 141 lines | [TEXT/CWIE] |
- // LDynamicPopupMenu.cp
- // written by Constantine Spathis
- // see LDynamicPopupMenu.h for more info
- //
- // 1/8/95 CS Initial Iteration
- // 97/05/20 P. Lamboley. See LDynamicPopupMenu.h
- //
-
- #include "LDynamicPopupMenu.h"
- #include "LString.h"
-
-
- // class variables
- Int16 LDynamicPopupMenu::mTitleWidth = 0;
- Int16 LDynamicPopupMenu::mTitleJust = popupTitleRightJust;
- Int16 LDynamicPopupMenu::mMenuID = first_menu_ID;
-
-
- // ---------------------------------------------------------------------------------
- // • LDynamicPopupMenu (LStream*)
- // ---------------------------------------------------------------------------------
- LDynamicPopupMenu::LDynamicPopupMenu (LStream* inStream)
- : LStdPopupMenu(inStream)
- { }
-
-
- // ---------------------------------------------------------------------------------
- // • CreateLDynamicPopupMenuStream (LStream*) [static]
- // ---------------------------------------------------------------------------------
- LDynamicPopupMenu*
- LDynamicPopupMenu::CreateLDynamicPopupMenuStream (LStream *inStream)
- {
- // Create a "normal" LStdPopup
- LDynamicPopupMenu *thePopup = new LDynamicPopupMenu (inStream);
-
- // Get old control title
- Str255 theTitle;
- LString::CopyPStr ( (**(thePopup->mMacControlH)).contrlTitle, theTitle);
-
- // Get old control Refcon
- long theRefCon = ::GetControlReference (thePopup->mMacControlH);
-
- // Get old control initial value
- Int32 theValue = thePopup->GetValue();
-
- // Get a copy of the menu, or a new one if the popup uses a resource list
- MenuHandle theMenu = thePopup->GetMacMenuH();
- if ( theRefCon == 0 || theRefCon == '????' )
- ::HandToHand ( (Handle*)&theMenu );
- else
- // theMenu = ::NewMenu (mMenuID, (**thePopup->mMacControlH).contrlTitle);
- theMenu = ::NewMenu (mMenuID, theTitle);
-
- // Here you really should add some code to check that menu was properly made
- // because HandToHand and NewMenu can fail. Just a suggestion :-)
- // xassert(ValidHandle(Handle(theMenu)));
-
- // Dispose of the control PowerPlant made
- ::DisposeControl(thePopup->mMacControlH);
-
- // The copy is for this control exclusive use
- (**theMenu).menuID = mMenuID;
-
- // make it hierarchical as needed for a popup
- ::InsertMenu (theMenu, ::hierMenu);
-
- // mMinValue holds the MenuID of the menu to link the control to.
- thePopup->mMinValue = mMenuID;
-
- // mValue holds the title justification : no way to retrieve it from the PPob
- thePopup->mValue = mTitleJust;
-
- // mMaxValue holds the title width : no way to retrieve it from the PPob
- if ( mTitleWidth < 0 )
- thePopup->mMaxValue = 4+StringWidth(theTitle);
- else
- thePopup->mMaxValue = mTitleWidth;
-
- // And make our own Control using PowerPlants StdControl maker
- thePopup->InitStdControl (thePopup->mControlKind, thePopup->mTextTraitsID, theTitle, theRefCon);
-
- /* ****** Plagirism On ******* */
-
- // See LStdPopupMenu::InitStdPopupMenu (which is private...)
- thePopup->mValue = ::GetControlValue (thePopup->mMacControlH);
- thePopup->mMinValue = ::GetControlMinimum(thePopup->mMacControlH);
- thePopup->mMaxValue = ::GetControlMaximum(thePopup->mMacControlH);
-
- // What use ?
- if (0 != thePopup->mValue) {
- ::SetControlValue (thePopup->mMacControlH, 0);
- thePopup->mValue = ::GetControlValue(thePopup->mMacControlH);
- }
-
- /* ****** Plagirism Off ******* */
-
- // Increment generated Menu ID
- mMenuID++;
-
- // Apply min and max and set the initial value (users can forget
- // FinishedCreatingMenu if they don't change the count of items)
- thePopup->FinishedCreatingMenu (theValue);
-
- return thePopup;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • FinishedCreatingMenu (Int32)
- // ---------------------------------------------------------------------------------
- void LDynamicPopupMenu::FinishedCreatingMenu (Int32 initialItem)
- {
- mMinValue = 1;
- mMaxValue = ::CountMItems ( GetMacMenuH() );
- SetStdMinAndMax();
- SetValue (initialItem);
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetTitleWidth (Int16)
- // ---------------------------------------------------------------------------------
- void LDynamicPopupMenu::SetTitleWidth (Int16 inWidth)
- {
- mTitleWidth = inWidth;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • SetTitleJust (Int16)
- // ---------------------------------------------------------------------------------
- void LDynamicPopupMenu::SetTitleJust (Int16 inJust)
- {
- mTitleJust = inJust;
- if (inJust != popupTitleLeftJust
- && inJust != popupTitleCenterJust
- && inJust != popupTitleRightJust )
- mTitleJust = popupTitleRightJust;
- }
-
-